package matrixCalculator;

import java.util.Random;

import Jama.Matrix;


/**
 * A Helper class used for matrix generation
 * Matrix operations 
 * Matrix answer generation
 * **/
public class MatrixHelper {

	public static Matrix generateMatrix(int size){
		
		double[][] matrixArray = new double[size][size];
		Random rGen = new Random();
		for(int i = 0; i< size; i++){
			for(int j = 0; j< size; j++){
				int num=rGen.nextInt(1000000);
				matrixArray[i][j] = num;
			}
		}
		
		Matrix a = new Matrix(matrixArray);
		
		
		return a;
		
	}
	
	public static Matrix multiplyMatrix(Matrix a, Matrix b){
		
		return a.times(b);
		
	}
	
	public static Matrix sumMatrix(Matrix a, Matrix b){
		return a.plus(b);
	}
	
	public static Matrix subsMatrix(Matrix a, Matrix b){
		
		return a.minus(b);
		
	}
	
	public static Matrix divideMatrix(Matrix a, Matrix b){
		
		return a.arrayLeftDivide(b);
	}
	
	public static String stringifyMatrix(Matrix matrix){
		String result = "";
		double[][] matrixAux = matrix.getArray();
		
		for(int i=0; i<matrixAux.length; i++ ){
       	 for(int j=0; j<matrixAux.length; j++ ){
       		 result=result.concat((String.valueOf(matrixAux[i][j]) + ","));
            }
       	result= result.concat("\n");
       }
	   return result;
	}
	
	public static synchronized void printMatriz(Matrix a){
		double[][] matrixArray =a.getArray();
		System.out.println("Size :" + matrixArray.length );
		
		for(int i=0; i<matrixArray.length; i++){
			for(int j=0; j<matrixArray.length; j++){
				System.out.print((int)matrixArray[i][j] + ",");
			}
			System.out.println();
		}
	}
	
}
